import * as THREE from 'three'
import { WuTi } from '../changJing/wuTi/WuTi.js'

/**
 * 互相不影响的更新函数集合
 * Map<Object, funtion>
 */ 
let gengXinJiHe = new Map()

// 帧更新函数
function gengXin(jianGeShi) {
	for (let [jian, zhi] of gengXinJiHe) {
		zhi(jianGeShi)
	}
}

function tongBu(wuTiCanShu) {
	// 从物理世界同步物体数据 用性能高的for循环
	for (let i = 0, il = wuTiCanShu.length; i < il; i++ ) {
		let canShu = wuTiCanShu[i] // 多次调[i] 赋值提性能
		for (let j = 0, jl = WuTi.quanBuWuTi.length; j < jl; j++ ) {
			let wuTi = WuTi.quanBuWuTi[j]
			if (wuTi.bianHao === canShu.bianHao) {
				wuTi.tongBu(canShu)
				break
			}
		}
	}
}

export {
	gengXinJiHe,
	gengXin,
	tongBu
}